package router

import (
	"encoding/json"
	"fmt"
	"io/ioutil"
	"net/http"
	"os"

	"github.com/gin-gonic/gin"
)

func GetDemo(c *gin.Context) {
	host, _ := os.Hostname()
	id := c.Query("id")
	start := c.Query("start")
	stop := c.Query("stop")
	req := make(map[string]interface{}, 0)
	req["id"] = id
	req["start"] = start
	req["stop"] = stop
	token := c.Request.Header.Get("Authorization")
	fmt.Printf("get:%+v\n", req)
	c.JSON(http.StatusOK, gin.H{
		"code":          0,
		"query":         req,
		"host":          host,
		"Authorization": token,
	})
}

func PostDemo(c *gin.Context) {
	host, _ := os.Hostname()
	req := make(map[string]interface{}, 0)
	body, _ := ioutil.ReadAll(c.Request.Body)
	json.Unmarshal(body, &req)
	token := c.Request.Header.Get("Authorization")
	fmt.Printf("post:%+v\n", req)
	c.JSON(http.StatusOK, gin.H{
		"code":          0,
		"body":          req,
		"host":          host,
		"Authorization": token,
	})
}
